Inventory registration in code

I need to write some code to receive items and assign a batch # during the receiving

So, As I understand he only way to assign a different vendor batch# is to do an inventory registration.

So can any one provide me with code sample for inventory registration and assigning batch or serial # in AX 2012?