// Set the end date time to have the line line item run till.
String endDateTime = "INSERT_END_DATE_TIME_HERE";
// Create prospective line item.
LineItem lineItem = new LineItem();
lineItem.setLineItemType(LineItemType.SPONSORSHIP);
lineItem.setTargeting(targeting);
// Create the creative placeholder.
CreativePlaceholder creativePlaceholder = new CreativePlaceholder();
creativePlaceholder.setSize(new Size(300, 250, false));
// Set the size of creatives that can be associated with this line item.
lineItem.setCreativePlaceholders(new CreativePlaceholder[] {creativePlaceholder});
// Set the line item's time to be now until the projected end date time.
lineItem.setStartDateTimeType(StartDateTimeType.IMMEDIATELY);
lineItem.setEndDateTime(DateTimeUtils.fromString(endDateTime));
// Set the line item to use 50% of the impressions.
lineItem.setUnitType(UnitType.IMPRESSIONS);
lineItem.setUnitsBought(50L);
// Set the cost type to match the unit type.
lineItem.setCostType(CostType.CPM);
// Get forecast for line item.
Forecast forecast = forecastService.getForecast(lineItem);
// Display results.