// Set the parent ad unit's ID for all ad units to be created under.
String effectiveRootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
// Create local ad unit object.
AdUnit adUnit = new AdUnit();
adUnit.setName("Video_Ad_Unit");
adUnit.setParentId(effectiveRootAdUnitId);
adUnit.setDescription("Ad unit description.");
adUnit.setTargetWindow(AdUnitTargetWindow.BLANK);
adUnit.setExplicitlyTargeted(true);
adUnit.setTargetPlatform(TargetPlatform.WEB);
// Create master ad unit size.
AdUnitSize masterAdUnitSize = new AdUnitSize();
masterAdUnitSize.setSize(new Size(400, 300, false));
masterAdUnitSize.setEnvironmentType(EnvironmentType.VIDEO_PLAYER);
// Create companion sizes.
AdUnitSize companionAdUnitSize1 = new AdUnitSize();
companionAdUnitSize1.setSize(new Size(300, 250, false));
companionAdUnitSize1.setEnvironmentType(EnvironmentType.BROWSER);
AdUnitSize companionAdUnitSize2 = new AdUnitSize();
companionAdUnitSize2.setSize(new Size(728, 90, false));
companionAdUnitSize2.setEnvironmentType(EnvironmentType.BROWSER);
// Add companions to master ad unit size.
masterAdUnitSize.setCompanions(new AdUnitSize[] {companionAdUnitSize1, companionAdUnitSize2});
// Set the size of possible creatives that can match this ad unit.
adUnit.setAdUnitSizes(new AdUnitSize[] {masterAdUnitSize});
// Create the ad unit on the server.
adUnit = inventoryService.createAdUnit(adUnit);
if (adUnit != null) {
System.out.println("An ad unit with ID \"" + adUnit.getId()
+ "\" was created under parent with ID \"" + adUnit.getParentId()
+ "\".");
} else {
System.out.println("No ad units created.");
}
} catch (Exception e) {