$lineItem = new LineItem();
     $lineItem->name = 'Line item #' . uniqid();
     $lineItem->orderId = $orderId;
     $lineItem->targeting = $targeting;
     $lineItem->lineItemType = 'STANDARD';
     $lineItem->allowOverbook = 'TRUE';
     // Create the creative placeholder.
     $creativePlaceholder = new CreativePlaceholder();
     $creativePlaceholder->size = new Size(300, 250, FALSE);
     // Set the size of creatives that can be associated with this line item.
     $lineItem->creativePlaceholders = array($creativePlaceholder);
     // Set the creative rotation type to even.
     $lineItem->creativeRotationType = 'EVEN';
     // Set the length of the line item to run.
     $lineItem->startDateTimeType = 'IMMEDIATELY';
     $lineItem->endDateTime = DateTimeUtils::GetDfpDateTime(new DateTime('+1 month'));
     // Set the cost per unit to $2.
     $lineItem->costType = 'CPM';
     $lineItem->costPerUnit = new Money('USD', 2000000);
     // Set the number of units bought to 500,000 so that the budget is
     // $1,000.
     $lineItem->unitsBought = 500000;
     $lineItem->unitType = 'IMPRESSIONS';
     $lineItems[] = $lineItem;
 }
 // Create the line items on the server.
 $lineItems = $lineItemService->createLineItems($lineItems);
 // Display results.
 if (isset($lineItems)) {
     foreach ($lineItems as $lineItem) {
         print 'A line item with with ID "' . $lineItem->id . '", belonging to order ID "' . $lineItem->orderId . '", and name "' . $lineItem->name . "\" was created.\n";
 $lineItem->lineItemType = 'SPONSORSHIP';
 // Create inventory targeting.
 $inventoryTargeting = new InventoryTargeting();
 $inventoryTargeting->targetedPlacementIds = array($targetPlacementId);
 // Set targeting for line item.
 $targeting = new Targeting();
 $targeting->inventoryTargeting = $inventoryTargeting;
 $lineItem->targeting = $targeting;
 // Create the creative placeholder.
 $creativePlaceholder = new CreativePlaceholder();
 $creativePlaceholder->size = new Size(300, 250, FALSE);
 // Set the size of creatives that can be associated with this line item.
 $lineItem->creativePlaceholders = array($creativePlaceholder);
 // Set the line item's time to be now until the projected end date time.
 $lineItem->startDateTimeType = 'IMMEDIATELY';
 $lineItem->endDateTime = DateTimeUtils::GetDfpDateTime(new DateTime('+1 week'));
 // Set the line item to use 50% of the impressions.
 $lineItem->unitType = 'IMPRESSIONS';
 $lineItem->unitsBought = 50;
 // Set the cost type to match the unit type.
 $lineItem->costType = 'CPM';
 // Get forecast for line item.
 $forecast = $forecastService->getForecast($lineItem);
 // Display results.
 $matchedUnits = $forecast->matchedUnits;
 $percentAvailableUnits = $forecast->availableUnits / $matchedUnits * 100;
 $unitType = strtolower($forecast->unitType);
 printf("%d %s matched.\n", $matchedUnits, $unitType);
 printf("%d%% %s available.\n", $percentAvailableUnits, $unitType);
 if (isset($forecast->possibleUnits)) {
     $percentPossibleUnits = $forecast->possibleUnits / $matchedUnits * 100;
 $lineItem->roadblockingType = 'ONE_OR_MORE';
 // Set the creative rotation type.
 $lineItem->creativeRotationType = 'OPTIMIZED';
 // Create the creative placeholder size.
 $size = new Size();
 $size->width = 300;
 $size->height = 250;
 $size->isAspectRatio = false;
 // Create the creative placeholder.
 $creativePlaceholder = new CreativePlaceholder();
 $creativePlaceholder->size = $size;
 // Set the size of creatives that can be associated with this line item.
 $lineItem->creativePlaceholders = array($creativePlaceholder);
 // Set the length of the line item to run.
 $lineItem->startDateTimeType = 'IMMEDIATELY';
 $lineItem->endDateTime = DateTimeUtils::GetDfpDateTime(new DateTime('+30 days', new DateTimeZone('America/New_York')));
 // Set the cost type.
 $lineItem->costType = 'CPM';
 // Set the line item to use 50% of the impressions.
 $goal = new Goal();
 $goal->goalType = 'DAILY';
 $goal->unitType = 'IMPRESSIONS';
 $goal->units = 50;
 $lineItem->primaryGoal = $goal;
 // Get forecast for prospective line item.
 $prospectiveLineItem = new ProspectiveLineItem();
 $prospectiveLineItem->lineItem = $lineItem;
 $options = new AvailabilityForecastOptions();
 $options->includeContendingLineItems = true;
 $options->includeTargetingCriteriaBreakdown = true;
 $forecast = $forecastService->getAvailabilityForecast($prospectiveLineItem, $options);