Rating Plugin
The Rating Plugin allows you to calculate charges for quotes and policy transactions. Pricing requests trigger the Rating Plugin. Once the plugin has been successfully executed and the pricing request has been processed, the quote or policy transaction will move to the priced state.
Charges can be associated with any element within a quote or policy transaction. Only one charge per charge type can be associated with each element. Charge types must be defined in the ChargeRef configuration object.
Supported Entity Types
The Rating Plugin supports the following entity types:
Quotes
Policy Transactions
Implementation
Create a new Java class in the src/main/java/com/socotra/deployment/customer folder. All plugin code must be contained within this folder. We named our class RatingPluginImpl.java in the example below, but you can name your class whatever you’d like.
Implement the RatePlugin interface, and override the method corresponding to the entity type you wish to rate.
For example, the following class rates commercial auto quotes:
public class RatingPluginImpl implements RatePlugin {
private static final Logger log = LoggerFactory.getLogger(RatingPluginImpl.class);
// Rate commercial auto quotes
@Override
public RatingSet rate(CommercialAutoQuoteRequest commercialAutoQuoteRequest) {
CommercialAutoQuote commercialAutoQuote = commercialAutoQuoteRequest.quote();
List<RatingItem> ratingItems = new ArrayList<>();
ratingItems.add(RatingItem.builder()
.elementLocator(commercialAutoQuote.locator())
.chargeType(ChargeType.adminFee)
.rate(BigDecimal.valueOf(50.0))
.build());
return RatingSet.builder().ok(true).ratingItems(ratingItems).build();
}
}
The method argument contains the entity to be rated.
The method returns a RatingSet object, which contains a list of RatingItem objects. Each RatingItem object contains the following fields:
elementLocator- The locator of the element to be ratedchargeType- The charge typerate- The rate
Examples
All examples are based on the Prism configuration. Contact your Socotra representative for more information.
Quote
// Calculate a premium for a commercial auto quote
@Override
public RatingSet rate(CommercialAutoQuoteRequest commercialAutoQuoteRequest) {
CommercialAutoQuote commercialAutoQuote = commercialAutoQuoteRequest.quote();
VehicleQuote vehicleQuote = commercialAutoQuote.vehicleSchedule().vehicles().stream().findFirst().orElseThrow();
double rate = 0.003 * vehicleQuote.data().currentValue().doubleValue() + 50;
List<RatingItem> ratingItems = new ArrayList<>();
ratingItems.add(RatingItem.builder()
.elementLocator(vehicleQuote.locator())
.chargeType(ChargeType.premium)
.rate(BigDecimal.valueOf(rate))
.build());
return RatingSet.builder().ok(true).ratingItems(ratingItems).build();
}
Policy Transaction
// Calculate a cargo charge for a commercial auto policy transaction
@Override
public RatingSet rate(CommercialAutoRequest commercialAutoRequest) {
List<RatingItem> ratingItems = new ArrayList<>();
if (commercialAutoRequest.segment().isPresent()) {
CommercialAutoSegment localSegment = commercialAutoRequest.segment().get();
if (localSegment.data().blanketCoverage()) {
BigDecimal rate = BigDecimal.valueOf(150.0);
int vehicleCount = localSegment.vehicleSchedule().vehicles().size();
rate = rate.multiply(BigDecimal.valueOf(vehicleCount));
RateModificationFactors rmfValues = localSegment.data().rateModificationFactors();
BigDecimal rmfFactor = BigDecimal.valueOf(rmfValues.serviceRmf().doubleValue()).multiply(BigDecimal.valueOf(rmfValues.maintenanceRmf().doubleValue()))
.multiply(BigDecimal.valueOf(rmfValues.seasonalityRmf().doubleValue())).multiply(BigDecimal.valueOf(rmfValues.territoryRmf().doubleValue()))
.multiply(BigDecimal.valueOf(rmfValues.fleetMgtRmf().doubleValue())).multiply(BigDecimal.valueOf(rmfValues.lossControlRmf().doubleValue()));
int driverCount = localSegment.driverSchedule().drivers().size();
BigDecimal driverFactor = BigDecimal.valueOf(1).add(BigDecimal.valueOf(driverCount).multiply(BigDecimal.valueOf(0.1)));
rate = rate.multiply(rmfFactor).multiply(driverFactor);
ratingItems.add(RatingItem.builder()
.elementLocator(localSegment.locator())
.chargeType(ChargeType.cargo)
.rate(rate)
.build());
}
}
return RatingSet.builder().ok(true).ratingItems(ratingItems).build();
}