// Set the line item to use 50% of the impressions.
lineItem.setUnitType(UnitType.IMPRESSIONS);
lineItem.setUnitsBought(50L);
// Get forecast for line item.
Forecast forecast = forecastService.getForecast(lineItem);
long matched = forecast.getMatchedUnits();
double availablePercent = (forecast.getAvailableUnits() / (matched * 1.0)) * 100;
String unitType = forecast.getUnitType().toString().toLowerCase();
System.out.printf("%d %s matched.\n", matched, unitType);
System.out.printf("%.2f%% %s available.\n", availablePercent, unitType);
if (forecast.getPossibleUnits() != null) {
double possiblePercent = (forecast.getPossibleUnits() / (matched * 1.0)) * 100;
System.out.printf("%.2f%% %s possible.\n", possiblePercent, unitType);
}
}