DMCommunity.org Jan-2018 Challenge is looking for a decision model that can define promotions for different sales orders. It provides a simple example of promotion: *reduce the total cost of the order by $3.50 if it contains at least 5 items 1108 and 4 item 2639. *Let’s build the proper decision model.

The problem formulation sounds simple. However, to determine if an order is eligible for a promotion we need to check if order’s items cover promotion’s requirements that may involve embedded iterations. To better understand the problem, let’s start with test data that usually is a good methodological approach.

First we specify an array of items assuming that each item has a unique id like “1108” or “2639” and a price. We will use an Excel table in the OpenRules format “Data”:

Now let’s create several orders. Each order has a unique id, say “AAA” and “BBB” and an array of order items included in an order. Here is an example:

The following table defines two orders:

The 3^{rd} row in this table uses “>orderItems” to refer to all order items defined above.

Similarly we may define an array of promotion items:

And here is an array of promotions that include some of these promotion items:

So, the first promotion will give a customer a $3.50 discount if his/her order contains at least 5 items 1108 and at least 4 items 2639. The second promotion will give a customer a $5.00 discount if his/her order contains at least 3 items 1112, 4 items 1723, and 2 items 1610.

We will use different combinations of these promotions and orders to test our future decision model that is supposed to determine its main goal “Order is Eligible To Promotion” as “YES” or “NO”. Actually, we already may specify a few test cases with expected results:

As you may guest, the Test-1 will check that the very first order (orders[0]) is eligible to the very first promotion (promotions[0]). Similarly other 3 test cases will validate the expected values for the pairs orders[0] – promotions[1], orders[1] – promotions[0], and orders[1] – promotions[1].

So, for each test case our decision model will receive one order and one promotion. To decide if an order is eligible to a promotion we need to check if every promotion item is present in the order in a sufficient quantity. Let’s present this logic in a decision table assuming that it deals with a Promotion Item and an Order Item. This table should define a new decision variable “Promotion Item Quantity Minimum Satisfied” that will belong to the business concept “PromotionItem”:

We need to execute this table for each promotion item and for each order item. To organize such iterations we can use OpenRules decision tables with a special predefined action “**ActionIterate**“. For example, the following decision table

will iterate through the array Order Items and will apply the above rules “ComparePromotionItemAndOrderQuantities” to each order item against the current Promotion Item. It also first set up the decision variable “Promotion Item Quantity Minimum Satisfied” to “NO”. After this iteration this variable may be changed to “YES”.

Now we need to call the table for every promotion item. It can be done using the following decision table:

By executing this decision table we will define the variable “Promotion Item Quantity Minimum Satisfied” as “YES” or “NO” for every promotion item relatively to the selected order.

Now we may use this variables to determine our goal (variable) “Order is Eligible To Promotion”. We can again iterate through all promotion items and if for at least one item its variable “Promotion Item Quantity Minimum Satisfied” has value “NO”, then we should set the variable “Order is Eligible To Promotion” to “NO”. But initially we may set up it to the default value “YES”. Here are the corresponding decision tables:

So, on the very top level our decision table should execute two steps:

To be able to execute our decision model we need to put all introduced decision variables in the glossary:

As we don’t want to use Java (yet), to complete our decision table in Excel we need to define data types for all PromotionItem, Promotion, OrderItem, and Order:

Now we can execute our decision model against the above 4 test cases. Here are the produced results for Tests 3 and 4:

The above decision tables can be easily extended to also calculate the complete and promotional costs for the given order and to define the discount as a percentage instead of an a fixed dollar amount.

The actual implementation Excel files will be included in the standard OpenRules installation.

Our readers can download them and use it with an evaluation version of OpenRules to run this decision model and/or to extend its functionality.

Pingback:Decision Model for Order Promotions |