The previous post on the JBoss Drools Rule Engine gave a high level overview of the benefits of using it in your web application. This post explores a concrete example. JPetstore is a simple shoppingcart application whose products are pets. This online petstore is included as a sample application with the Spring Framework bundle to highlight some of Spring’s capabilities. What follows is how I modified JPetstore to leverage the JBoss Drools Rule Engine 5.2 (the commercial version offered by Red Hat is called JBoss Rules) so JPetstore could have some of the features we commonly see offered by online retailers.
It is common to see online retailers give customers who enter a coupon code during checkout a special offer. Some examples are:
- Buy 3 goldfish, get the 4th free.
- Buy “camera model A” and get “tripod model B” for free
- 10% off your order cost when you enter offer code X
- All batteries 20% off when using promo code X
- $10 off any order totaling over $100
- Buy any 3 car care products, get a free microfiber towel.
- Free shipping using code X
Many offers of this type are valid for only a short period of time – a week, a weekend, or even a single day (Black Friday offers).
This functionality calls for using a Rule Engine.
A rule engine could also serve as a “recommendation engine” – it can be used to recommend or suggest additional products to the customer based on their past orders, their user profile, etc. For instance, if you purchased car wax, the system might recommend their bestselling microfiber towel or something specific to your car’s year/make/model.
JBoss Drools Expert (or JBoss Rules for the enterprise version of Drools supported by Red Hat) is a business rule engine. You may have heard of a Rule Engine in the past but were unsure of how it can benefit you and your application. In the following paragraphs, I will list some of the benefits of using a Rule Engine in a traditional web application, the different formats used to express rules in Drools, and a general overview of how Drools is used.