I would say, this is one of those cases where it is best to use the right tool for the right job. A programmer can implement this in pure DRL using a few rules, but I don't like the idea, because it will be hard for others to quickly grasp the meaning of the rules. So, I would implement a function (either simple or an accumulate function) to calculate the number of free items and use the rules for what they do best: act on the results.

    The rule would be like:

rule "add free items"
where
    Brand( $name : name, includedInPromotion == true )
    Number( $free : intValue > 0 ) from accumulate(
             $i : Item( brand == $name ),
             calculateFree( $i ) )
then
    // add $free items to the order
end

    Take a look at the docs on how to implement the function to calculate the number of free items. It is very simple.
    This way, your business rule above is clear and easy to understand/maintain.

    Hope it helps.

    []s
    Edson

2009/1/23 niraj manandhar <regniraj@gmail.com>
I have following plan for the free item distribution

purchase of 3 items under a same  brands will get 1 gift item free
purchase of 5 items under a same  brands will get 2  gift item free
purchase of 10 items under a same  brands will get 4  gift item free


now if some buyer buys 13 items then he wil get free ites
4 for first 10
1 for the remaining 3

tell me how to make a drl with this thing'




_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com