Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This sample demonstrates a service for specifying the charge rates for calls through the use of business rules.

...

Sample Configuration

Table of Contents
maxLevel4
minLevel4


Sample Rule Definition

...


Rules

Rule 1 : If a local calls was taken during daytime, then the call rate is two dollars per minute.

Rule 2 : If a local call was taken during night, then the call rate is one dollar per minute.

Rule 3 : If an international call was taken during daytime, then the call rate is six dollars per minute.

Rule 4 : If an international was taken during night, then the call rate is four dollars per minute.


Facts

There is one fact named A call has been taken (CallLog). a charge should be calculated for the call (CallCharge) is the result of the rule execution.

 

Code Block
languagejava
package samples.callcharging;
import java.util.Calendar;

/**
 * CallLog fact
 */
public class CallLog {

    private String type;

    private double period;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public double getPeriod() {
        return period;
    }

    public void setPeriod(double period) {
        this.period = period;
    }

    public int now() {
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.HOUR_OF_DAY);
    }
}

package samples.callcharging;

/**
 * CallCharge fact
 */
public class CallCharge {

    private double amount;

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }
}

Rule Service Configuration (service.rsl)

An in-line rule set is used within the service.rsl file as follows.

...