// Create an array to store local line item objects.
LineItem[] lineItems = new LineItem[5];
for (int i = 0; i < 5; i++) {
LineItem lineItem = new LineItem();
lineItem.setName("Line item #" + i);
lineItem.setOrderId(orderId);
lineItem.setTargeting(targeting);
lineItem.setLineItemType(LineItemType.STANDARD);
lineItem.setAllowOverbook(true);
// 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);
lineItems[i] = lineItem;
}
// Create the line items on the server.
lineItems = lineItemService.createLineItems(lineItems);
if (lineItems != null) {
for (LineItem lineItem : lineItems) {
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 items created.");
}
} catch (Exception e) {