Targeting targeting = new Targeting();
targeting.setInventoryTargeting(inventoryTargeting);
targeting.setTechnologyTargeting(technologyTargeting);
// Create local line item object.
LineItem lineItem = new LineItem();
lineItem.setName("Mobile line item");
lineItem.setOrderId(orderId);
lineItem.setTargeting(targeting);
lineItem.setLineItemType(LineItemType.STANDARD);
lineItem.setAllowOverbook(true);
// Set the target platform to mobile.
lineItem.setTargetPlatform(TargetPlatform.MOBILE);
// Set the creative rotation type to even.
lineItem.setCreativeRotationType(CreativeRotationType.EVEN);
// 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 length of the line item to run.
lineItem.setStartDateTimeType(StartDateTimeType.IMMEDIATELY);
lineItem.setEndDateTime(DateTimeUtils.fromString("2012-09-01T00:00:00"));
// Set the cost per unit to $2.
lineItem.setCostType(CostType.CPM);
lineItem.setCostPerUnit(new Money("USD", 2000000L));
// Set the number of units bought to 500,000 so that the budget is
// $1,000.
lineItem.setUnitsBought(500000L);
lineItem.setUnitType(UnitType.IMPRESSIONS);
// Create the line item on the server.
lineItem = lineItemService.createLineItem(lineItem);
if (lineItem != null) {
System.out.println("A line item with ID \"" + lineItem.getId()
+ "\", belonging to order ID \"" + lineItem.getOrderId() + "\", and named \""
+ lineItem.getName() + "\" was created.");
} else {
System.out.println("No line item created.");
}
} catch (Exception e) {
e.printStackTrace();