Create Nested Rule

In this example, we will determine whether a shipping fee should be applied for a product. The decision will be based on the following criteria:

  • The product's discount rate (retrieved from the previously defined discount rule)

  • The product's category (e.g., fashion )

Kurallar şöyle:

  1. For products with a discount rate of 25% or higherShipping is charged

  2. For all products in the fashion categoryShipping is always charged

  3. For products with no discount or a discount rate below 25%Shipping is free

Product Category
Discount Rate (%)
Shipping Fee

Fashion

Any

Charged

Any

≥ 25

Charged

Any

< 25

Free

Note: The fashion category always has priority. This means that even if a fashion item has only a 10% discount, shipping will still be charged.

Input and Output Definition

  • Input:

    • product_type

    • discount_rate (Discount rate, value returned from the discount rule)

  • Output:

    • paid (boolean) — Indicates whether the shipping fee will be charged

      • true → Shipping fee will be charged

      • false → Shipping fee will not be charged

  • We set the default value of the paid return parameter to false (i.e., shipping is free).

  • However, since shipping is always charged for the fashion category,

  • we create a separate decision table based on the product_typeparameter.

  • In this decision table, when product_type = fashion, the paid value will return true (shipping charged).

  • In the decision table, when the product_type value is "Fashion",

  • The return parameter paid is set to true (i.e., shipping is charged).

  • Since the shipping fee needs to be determined based on the discount rate, we create a new decision table named "Based on Discount Rate".

  • In this table, the discount rate parameter will be defined using the Greater Than or Equal To (≥) comparison operator.

  • Thus, shipping fees can be applied for cases where the discount rate is equal to or greater than the specified value.

If the discount rate is ≥ 25%, then paid is set to true (shipping fee charged).

Rule definition is complete.

Testing

  • Category: Toys

  • Amount: 100

Status: In the discount rule, a 30% discount is defined for the Toys category. In the shipping fee rule, it is decided that shipping is charged for discounts of 25% or more.

Result: According to this test, since the discount is 30%, the shipping fee will be charged (PAID = true).

  • Category: Fashion

  • Amount: 10

Status: In the discount rule, it is defined that a 15% discount applies to amounts between 0 and 500 TL for the Fashion category. In the shipping fee rule, there is a rule stating that shipping is always charged for the Fashion category, and this rule has priority in the order.

Result: Therefore, regardless of the discount rate, the shipping fee will be charged (PAID = true).

Last updated