Red Hat Training
A Red Hat training course is available for JBoss Enterprise SOA Platform
Chapter 26. Pricing Rule Example
26.1. Pricing Rule Example: Executing the Pricing Rule Example
Procedure 26.1. Task
- Open your console.
- Open the file
PricingRuleDTExample.java
and execute it as a Java application. It will produce the following output in the console window:Cheapest possible BASE PRICE IS: 120 DISCOUNT IS: 20
- Use the following code to execute the example:
DecisionTableConfiguration dtableconfiguration = KnowledgeBuilderFactory.newDecisionTableConfiguration(); dtableconfiguration.setInputType( DecisionTableInputType.XLS ); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); Resource xlsRes = ResourceFactory.newClassPathResource( "ExamplePolicyPricing.xls", getClass() ); kbuilder.add( xlsRes, ResourceType.DTABLE, dtableconfiguration );
TheDecisionTableConfiguration
object's type is set toDecisionTableInputType.XLS
.There are two fact types used in this example,Driver
andPolicy
. Both are used with their default values. TheDriver
is 30 years old, has had no prior claims and currently has a risk profile ofLOW
. ThePolicy
being applied for isCOMPREHENSIVE
, and it has not yet been approved.
26.2. Pricing Rule Example: Decision Table Configuration
Figure 26.1. Decision Table Configuration
- The
RuleSet
declaration provides the package name. There are also other optional items you can put here, such asVariables
for global variables, andImports
for importing classes. In this case, the namespace of the rules is the same as the fact classes and thus can be omitted. - The name after the
RuleTable
declaration (Pricing bracket) is used as the prefix for all the generated rules. - "CONDITION or ACTION", indicates the purpose of the column, that is, whether it forms part of the condition or the consequence of the rule that will be generated.
- The driver's data is spread across three cells which means that the template expressions below it are applied. You can observe the driver's age range (which uses
$1
and$2
with comma-separated values),locationRiskProfile
, andpriorClaims
in the respective columns. - You can set a policy base price and message log in the Action column.
26.3. Pricing Rule Example: Base Price Calculation Example
Figure 26.2. Base Price Calculation Example
- Broad category brackets are indicated by the comment in the leftmost column.
- The details of the drivers match row number 18 as they have no prior accidents and are 30 years old. This gives us a base price of 120.
26.4. Pricing Rule Example: Discount Calculation Example
Figure 26.3. Discount Calculation Example
- The discount results from the
Age
bracket, the number of prior claims, and the policy type. - The driver is 30 with no prior claims and is applying for a
COMPREHENSIVE
policy. This means a 20% discount can be applied. Note that this is actually a separate table in the same worksheet, so different templates apply. - The evaluation of the rules is not necessarily in the given order, since all the normal mechanics of the rule engine still apply.