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

  1. Open your console.
  2. 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
  3. 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 );
    
    The DecisionTableConfiguration object's type is set to DecisionTableInputType.XLS.
    There are two fact types used in this example, Driver and Policy. Both are used with their default values. The Driver is 30 years old, has had no prior claims and currently has a risk profile of LOW. The Policy being applied for is COMPREHENSIVE, and it has not yet been approved.

26.2. Pricing Rule Example: Decision Table Configuration

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 as Variables for global variables, and Imports 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, and priorClaims 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

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

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.