Hello dokusan!
You can get free margin by dividing IAccount.getCredtLine() by IAccount.getLeverage().
But you should know, that your order won't be rejected if order's amount is bigger than free margin. It's more complicated: for example you want to buy 1,000,000 EUR for USD (aka open long position with EUR/USD instrument), if current ASK price is 1.15899, then you need 1,158,990 USD to buy 1,000,000 EUR. As there is default leverage equals to 100, then you need 1,158,990 / 100 = 11,589.9 USD margin available to open this position. So that means if you want to open long EUR/USD position with amount 1,000,000 when ASK price is 1.15899 you need 11,589.9 USD of free margin available, if you don't - your order still will be submitted, but during execution it will be partially filled with maximum amount possible for free margin available.
See "Margin Requirements" section here:
https://www.dukascopy.com/wiki/#Market_Order