views:

136

answers:

4

Hi there, I'm developing a price calculation engine. I've looked all over and there's nothing that really fits what we need. However, I'm now looking how to implement specific prices and/or discounts. I don't want to introduce a rule based engine to my end-users, because they won't get it.

For example, when you order an ItemX the price is $30. But in combination with ItemY the price of ItemX is $20. Or when ordering five of ItemX, each after it will be only $15.

Any ideas on where to start? How to take this on? Perhaps some (open source) example applications that contain practices like these? Any (technical) patterns I could use? Preferably in C#. Thanks in advance!

A: 

I am sorry to have to say this, but this would seem like you would have to apply some Pricing Rule Engine to achive what you are after.

Would seem like you have to

  • Store the available items, and their discounts on per pruchase.
  • Store which items in combination would discount each other.
  • Also maybe thinking of per unit/quantity purchased per unit, or maybe per package/special.
  • Might want to look at keeping a archive/storage of these specials/packages, just incase the customer wants a reprint of the original invoice.

In general there is a lot of possible rules/combinations that can be thought of, and you as developer can implement these and hide them from the user, or allow the user to create them, but somebody has to do so.

And then, when you dont feel like implementing your own, GOOGLE shold provide some:

Open Source Rule Engines

astander
+2  A: 

There are many ways you can achieve this, but I think the one which might be most useful for you would be to define a DSL that you can use to express your discounts in such a way where they can be easily explained and rationalised with business users. An example from one of ayende's articles on DSLs in boo is:

apply_discount_of 5.percent:
     when order.Total > 1000 and customer.IsPreferred
     when order.Total > 10000

suggest_registered_to_preferred:
     when order.Total  > 100 and not customer.IsPreferred

As you can see you can see, this is the kind of thing you can print out and show to a client and they will immediately understand what's going on.

Of course developing something like this is time consuming, expensive and fraught with funky edge cases. However it has the benefit of being code which can be unit tested, executed and debugged.

If boo isn't your thing, then maybe you could look at defining something similar in ironruby, ironpython or F#. I would however suggest staying away from XML for defining these rules unless you really enjoy a world of pain.

This is however the kind of thing that products like Biztalk were designed to handle. Which rules engines have you evaluated and found lacking?

jonnii
I think the DSL option is the best, I don't want to give my customer this. They don't understand it, will make errors and I don't have time to implement the exceptions, because there will be many!!! But thanks anyway, maybe I'll look into it some time.
Dennis van der Stelt
A: 

We use a Rule Engine for this type of complex calculation. Our platform is Java and we use Drools (which we're happy with). Drools is also available for .Net. Here's a list of open source Rules Engines for .NET.

Eric J.
+1  A: 

Busy looking at a similar situation and find the Decorator pattern to be a good option.

http://www.dofactory.com/Patterns/PatternDecorator.aspx

Check out: http://www.itarchitect.co.uk/articles/display.asp?id=357

Cheers

Also check for a strat type pattern I am looking at for implementing discounts: http://stackoverflow.com/questions/2253475/discount-strategy-in-shopping-cart-and-orders

Chev
I also think decorator is the best solution. I'm doing a mix of chain-of-responsibility to find out what 'module' is appropriate for the specific product-range and than add decorator for specific adjustments.
Dennis van der Stelt