// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the InventoryService.
InventoryServiceInterface inventoryService =
user.getService(DfpService.V201308.INVENTORY_SERVICE);
// Get the NetworkService.
NetworkServiceInterface networkService =
user.getService(DfpService.V201308.NETWORK_SERVICE);
// Set the parent ad unit's ID for all ad units to be created under.
String effectiveRootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
// Create an array to store local ad unit objects.
AdUnit[] adUnits = new AdUnit[5];
for (int i = 0; i < 5; i++) {
AdUnit adUnit = new AdUnit();
adUnit.setName("Ad_Unit_" + i);
adUnit.setParentId(effectiveRootAdUnitId);
adUnit.setDescription("Ad unit description.");
adUnit.setTargetWindow(AdUnitTargetWindow.BLANK);
// Create ad unit size.
AdUnitSize adUnitSize = new AdUnitSize();
adUnitSize.setSize(new Size(300, 250, false));
adUnitSize.setEnvironmentType(EnvironmentType.BROWSER);
// Set the size of possible creatives that can match this ad unit.
adUnit.setAdUnitSizes(new AdUnitSize[] {adUnitSize});
adUnits[i] = adUnit;
}
// Create the ad units on the server.
adUnits = inventoryService.createAdUnits(adUnits);
if (adUnits != null) {
for (AdUnit adUnit : adUnits) {
System.out.println("An ad unit with ID \"" + adUnit.getId()
+ "\" was created under parent with ID \"" + adUnit.getParentId()